home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr11
/
pdox693.zip
/
TI538.ASC
< prev
next >
Wrap
Text File
|
1992-09-03
|
11KB
|
463 lines
PRODUCT : Paradox NUMBER : 538
VERSION : All
OS : DOS
DATE : September 3, 1992 PAGE : 1/7
TITLE : Why, How and When to Use the PAL Wait Command
┌───────────────────────────────────────────────────────────────┐
│ │
│ This Technical Information Sheet is a teaching aid for │
│ people who are new to PAL. It contains PAL code to demon- │
│ strate a model solution to a specific problem and is not │
│ intended to represent a complete programming solution. │
│ Programmers who use this code must take responsibility for │
│ debugging and developing their application. Debugging and │
│ developing applications is considered consulting and is │
│ beyond the scope of technical support. │
│ │
└───────────────────────────────────────────────────────────────┘
Note: before working with this Technical Information Sheet,
change to the directory containing the sample tables
(C:\PDOX35\SAMPLE by default) and make sure that the CUSTOMER,
PRODUCTS, and ORDERS tables are available.
If you play a script containing the command:
EDIT "Customer"
the table Customer will be on the workspace in Edit mode, and you
will be able to edit it as usual. However, you are no longer
under script control while you edit the table. Without the WAIT
command, problems can arise, One such problem is illustrated in
the following script:
WHILE true
SHOWMENU
"Edit" : "Edit Customer",
"Leave" : "Exit script"
TO Choice
SWITCH
CASE Choice = "Edit" :
EDIT "Customer"
CASE Choice = "Leave" :
QUITLOOP
ENDSWITCH
ENDWHILE
After you play this script, and choose the Edit option, you find
yourself right back at the menu. What happened? The script
PRODUCT : Paradox NUMBER : 538
VERSION : All
OS : DOS
DATE : September 3, 1992 PAGE : 2/7
TITLE : Why, How and When to Use the PAL Wait Command
continued when it encountered the EDIT command; nothing told it
to stop and accept user input. (If you choose Edit again, you
receive a script error because the table is already in Edit
mode.)
A PAL program continues, regardless of the state of the
workspace, until a PAL command is used to stop it.
The solution to this problem is the WAIT command. The rest of
this document gives a summary of WAIT, focusing on how and when
to use it. For further information, including an explanation of
WAIT syntax, see Chapter 20 of the PAL User's Guide. For more
information on the UNTIL clause, see TI 697 (UNTIL clause in WAIT
TABLE, RECORD, and FIELD).
The WAIT command allows the user to interact with an on-screen
image, in Tableview or Formview, until they press a key that
allows your program to take control again. The following script
demonstrates how to edit an on-screen image using the WAIT
command:
;Begin example
WHILE true
SHOWMENU
"Edit" : "Edit Customer",
"Leave" : "Exit script"
TO Choice
SWITCH
CASE Choice = "Edit" :
EDIT "Customer"
WAIT TABLE ;Note this addition from
UNTIL "F2", "Esc" ;previous example
IF retval = "F2" THEN ;Did user press F2?
DO_IT! ;Yes, save work
ELSE
CANCELEDIT ;No, abort edit
ENDIF
PRODUCT : Paradox NUMBER : 538
VERSION : All
OS : DOS
DATE : September 3, 1992 PAGE : 3/7
TITLE : Why, How and When to Use the PAL Wait Command
CLEARIMAGE ;Clean up workspace
CLEAR
CASE Choice = "Leave" :
QUITLOOP ;could be QUIT or RETURN
ENDSWITCH
ENDWHILE
; End example
With the addition of the WAIT command, you can now view and edit
the table on the screen. What happened? First of all, WAIT
allows you to see the Paradox workspace, instead of the PAL
canvas. For more information on this topic, see Chapter 13 of
the PAL User's Guide.
Secondly, WAIT allows the user to interact with the table until
they push one of the special keys, <F2> and <ESC>. The WAIT then
exits, and the PAL script continues normally. The system
variable RETVAL contains the keystroke that caused WAIT to exit.
Use IF or SWITCH to determine the processing that takes place
after the WAIT.
Use WAIT RECORD when you want your PAL application to regain
control between records. The following example illustrates the
use of WAIT RECORD to handle key violations (Note that a network
application would require much more error checking):
; --- Begin example for WAIT RECORD ---
VIEW "Customer"
WHILE true
WAIT TABLE ;This allows user to browse the
;table in Main mode
PROMPT "Press F2 to exit",
"Press F9 to edit a record or Ins to add one"
UNTIL "F2", "F9", "Ins"
IF retval = "F2" THEN
PRODUCT : Paradox NUMBER : 538
VERSION : All
OS : DOS
DATE : September 3, 1992 PAGE : 4/7
TITLE : Why, How and When to Use the PAL Wait Command
QUITLOOP
ELSE
COEDITKEY
IF retval = "Ins" THEN ;Notice how we make the same
INS ;ELSE work for both the <F9>
ELSE ;and <INS> keys with this IF.
LOCKRECORD
ENDIF
KeyViolPrompt = ""
WHILE true
WAIT RECORD ;Now force the user to stay
;within the record while they
;edit it
PROMPT "Press F2 to finish editing or Esc to cancel",
KeyViolPrompt
UNTIL "F2", "Esc"
SWITCH
CASE retval = "F2" :
UNLOCKRECORD
IF RECORDSTATUS("KeyViol") THEN
KeyViolPrompt = "Key Violation: modify record"
[] = [] ;This command takes the record
;out of KeyViol status
ELSE ;Record must be OK
DO_IT!
QUITLOOP
ENDIF
CASE retval = "Esc" :
UNDO ;UNDO does not normally work well
;in Coedit mode, but here we only
PRODUCT : Paradox NUMBER : 538
VERSION : All
OS : DOS
DATE : September 3, 1992 PAGE : 5/7
TITLE : Why, How and When to Use the PAL Wait Command
;modify a single record
DO_IT!
QUITLOOP
ENDSWITCH
ENDWHILE
ENDIF
ENDWHILE
CLEARIMAGE
; --- End example for WAIT RECORD ---
WAIT FIELD provides the most complete control within an
application. Use it for controlling cursor movement between
fields and for field validation.
; --- Begin example for WAIT FIELD ---
VIEW "Products"
EDIT "Orders"
END
DOWN
WHILE true
WAIT FIELD
PROMPT "Press 'F2' to finish or 'Esc' to cancel"
UNTIL "F2", "Esc", "Enter"
SWITCH
CASE retval = "F2" :
DO_IT!
CLEARALL
RETURN
CASE retval = "Esc" :
CANCELEDIT
QUITLOOP ;Note CLEARIMAGEs at bottom
CASE retval = "Enter" : ;User pressed movement key to
PRODUCT : Paradox NUMBER : 538
VERSION : All
OS : DOS
DATE : September 3, 1992 PAGE : 6/7
TITLE : Why, How and When to Use the PAL Wait Command
;try to continue to next
;field
BadQuant = false
IF FIELD() = "Quant" THEN ;Check which field user is in
Quant = []
StockNum = [Stock #]
UPIMAGE
MOVETO [Stock #]
LOCATE StockNum ;Assume StockNum exists
IF Quant > [Quant] THEN ;Make sure there is enough
BadQuant = true ;stock available
ENDIF
MOVETO "Orders"
ENDIF
IF NOT BadQuant THEN
ENTER
ELSE
MESSAGE "Not enough stock available"
SLEEP 1000
ENDIF
ENDSWITCH
ENDWHILE
CLEARIMAGE CLEARIMAGE
; --- End example for WAIT FIELD ---
In summary, use WAIT to allow the user access to the workspace
and control what they do there. WAIT TABLE allows the user
access to the entire table, WAIT RECORD restricts the user to one
record at a time, and WAIT FIELD restricts the user to one field
at a time.
Advanced programmers with a thorough knowledge of procedures and
libraries may want to use the Data Entry Toolkit, described in
Chapter 23 of the PAL User's Guide.
PRODUCT : Paradox NUMBER : 538
VERSION : All
OS : DOS
DATE : September 3, 1992 PAGE : 7/7
TITLE : Why, How and When to Use the PAL Wait Command
DISCLAIMER: You have the right to use this technical information
subject to the terms of the No-Nonsense License Statement that
you received with the Borland product to which this information
pertains.